文章目录
  1. 1. 系统运维|如何在 CentOS 7 上安装 Docker
  2. 2. CentOS 7 中 Docker 的安装
    1. 2.0.1. 启动 Docker 服务
  • 3. centos修改docker镜象存储与容器目录
  • 系统运维|如何在 CentOS 7 上安装 Docker

    centOS docker

    CentOS 7 中 Docker 的安装

    Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。因此想要安装 docker,只需要运行下面的 yum 命令:

    [root@localhost ~]#yum install docker
    

    启动 Docker 服务

    安装完成后,使用下面的命令来启动 docker 服务,并将其设置为开机启动:

    [root@localhost ~]# service docker start[root@localhost ~]# chkconfig docker on
    

    (LCTT 译注:此处采用了旧式的 sysv 语法,如采用CentOS 7中支持的新式 systemd 语法,如下:

    [root@localhost ~]#systemctl  start docker.service[root@localhost ~]#systemctl  enable docker.service
    

    )

    下载官方的 CentOS 镜像到本地 (LCTT 译注:由于 Docker 被墙 :-< ,所以请使用 http://docker.cn  的镜像,感谢 @马全一 的镜像。 )

    [root@localhost ~]# docker pull centosPulling repository centos192178b11d36:Download complete 70441cac1ed5:Download complete ae0c2d0bdc10:Download complete 511136ea3c5a:Download complete 5b12ef8fd570:Download complete
    

    确认 CentOS 镜像已经被获取:

    [root@localhost ~]# docker images centosREPOSITORY    TAG          IMAGE ID      CREATED       VIRTUAL SIZEcentos        centos5      192178b11d362 weeks ago   466.9 MBcentos        centos6      70441cac1ed52 weeks ago   215.8 MBcentos        centos7      ae0c2d0bdc10  2 weeks ago   224 MBcentos        latest       ae0c2d0bdc10  2 weeks ago   224 MB
    

    运行一个 Docker 容器:

    [root@localhost ~]# docker run -i -t centos /bin/bash[root@dbf66395436d /]#
    

    我们可以看到,CentOS 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。

    [root@cd05639b3f5c /]#cat/etc/redhat-release CentOSLinux release 7.0.1406(Core)[root@cd05639b3f5c /]#exitexit[root@localhost ~]#
    

    我们还可以搜索基于 Fedora 和 Ubuntu 操作系统的容器。

    [root@localhost ~]# docker search ubuntu[root@localhost ~]# docker search fedora
    

    显示当前正在运行容器的列表

    205536tmq6hzl6mq165sqq.png


    修改docker默认的容器目录

     

    centos修改docker镜象存储与容器目录

    vim /usr/lib/systemd/system/docker.service

    修改如下:

    [Unit]

    Description=Docker Application Container Engine

    Documentation=http://docs.docker.com

    After=network.target rhel-push-plugin.socket registries.service

    Wants=docker-storage-setup.service

    Requires=docker-cleanup.timer

    ``

    [Service]

    Type=notify

    NotifyAccess=all

    EnvironmentFile=-/run/containers/registries.conf

    EnvironmentFile=-/etc/sysconfig/docker

    EnvironmentFile=-/etc/sysconfig/docker-storage

    EnvironmentFile=-/etc/sysconfig/docker-network

    Environment=GOTRACEBACK=crash

    Environment=DOCKER_HTTP_HOST_COMPAT=1

    Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin

    ExecStart=/usr/bin/dockerd-current \

       -g /mnt/docker \

      --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \

      --default-runtime=docker-runc \

      --exec-opt native.cgroupdriver=systemd \

      --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \

      --init-path=/usr/libexec/docker/docker-init-current \

      --seccomp-profile=/etc/docker/seccomp.json \

      $OPTIONS \

      $DOCKER_STORAGE_OPTIONS \

      $DOCKER_NETWORK_OPTIONS \

      $ADD_REGISTRY \

      $BLOCK_REGISTRY \

      $INSECURE_REGISTRY \

      $REGISTRIES

    ExecReload=/bin/kill -s HUP $MAINPID

    LimitNOFILE=1048576

    LimitNPROC=1048576

    LimitCORE=infinity

    TimeoutStartSec=0

    Restart=on-abnormal

    KillMode=process

    ``

    [Install]

    WantedBy=multi-user.target

    保存后,重启docker

    service docker restart
    

    重启时提示需要更新systemctl

    systemctl daemon-reload
    

    Measure

    Measure

    centos 7

    阿里云安装docker

    yum install docker

    —停止docker

    service docker stop

    —查看docker配置信息

       docker info

    — 启动docker

     service docker start

    文章目录
    1. 1. 系统运维|如何在 CentOS 7 上安装 Docker
    2. 2. CentOS 7 中 Docker 的安装
      1. 2.0.1. 启动 Docker 服务
  • 3. centos修改docker镜象存储与容器目录